//
//  GSHomeViewController.m
//  GSDemo
//
//  Created by ZhangFujie on 2022/10/12.
//

#import "GSHomeViewController.h"
#import "ZFJPopManagerHeader.h"

@interface GSHomeViewController ()

@end

@implementation GSHomeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    UIButton *button = [[UIButton alloc] init];
    button.backgroundColor = kRandomColor();
    [button addTarget:self action:@selector(buttonClick) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];
    [button mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view).offset(100);
        make.centerX.equalTo(self.view);
        make.width.height.mas_equalTo(100);
    }];
    
    UIButton *button1 = [[UIButton alloc] init];
    button1.backgroundColor = kRandomColor();
    [button1 addTarget:self action:@selector(button1Click) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button1];
    [button1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(button.mas_bottom).offset(100);
        make.centerX.equalTo(self.view);
        make.width.height.mas_equalTo(100);
    }];
}

- (void)buttonClick{
    NSMutableArray *dataArray = [[NSMutableArray alloc] init];
    
    /// 第一个弹窗
    UILabel *customPopView0 = [[UILabel alloc] init];
    customPopView0.backgroundColor = kRandomColor();
    customPopView0.frame = CGRectMake(0, 0, 250, 250);
    customPopView0.font = [UIFont systemFontOfSize:80];
    customPopView0.textAlignment = NSTextAlignmentCenter;
    customPopView0.textColor = UIColor.whiteColor;
    customPopView0.layer.masksToBounds = YES;
    customPopView0.layer.cornerRadius = 8;
    ZFJPopModel *model0 = [[ZFJPopModel alloc] init];
    /// 自定义弹窗
    model0.customPopView = customPopView0;
    /// 延迟弹出的时间
    model0.popDelay = 0;
    /// 倒计时自动关闭
    model0.countDownStop = 5;
    /// 动画样式
    model0.animateStyle = ZFJAnimateFromTop;
    [dataArray addObject:model0];
    
    /// 第二个弹窗
    UIView *customPopView1 = [[UIView alloc] init];
    customPopView1.backgroundColor = kRandomColor();
    customPopView1.frame = CGRectMake(0, 0, 200, 300);
    customPopView1.layer.masksToBounds = YES;
    customPopView1.layer.cornerRadius = 8;
    
    ZFJPopModel *model1 = [[ZFJPopModel alloc] init];
    /// 自定义弹窗
    model1.customPopView = customPopView1;
    /// 延迟弹出的时间
    model1.popDelay = 0;
    /// 动画样式
    model1.animateStyle = ZFJAnimateFromLeft;
    [dataArray addObject:model1];
    
    /// 第三个弹窗
    UIView *customPopView2 = [[UIView alloc] init];
    customPopView2.backgroundColor = kRandomColor();
    customPopView2.frame = CGRectMake(0, 0, 350, 100);
    customPopView2.layer.masksToBounds = YES;
    customPopView2.layer.cornerRadius = 8;
    ZFJPopModel *model2 = [[ZFJPopModel alloc] init];
    /// 自定义弹窗
    model2.customPopView = customPopView2;
    /// 延迟弹出的时间
    model2.popDelay = 0;
    /// 动画样式
    model2.animateStyle = ZFJAnimateFromRight;
    [dataArray addObject:model2];
    
    /// 第四个弹窗
    UIView *customPopView3 = [[UIView alloc] init];
    customPopView3.backgroundColor = kRandomColor();
    customPopView3.frame = CGRectMake(0, 0, 200, 350);
    customPopView3.layer.masksToBounds = YES;
    customPopView3.layer.cornerRadius = 8;
    ZFJPopModel *model3 = [[ZFJPopModel alloc] init];
    /// 自定义弹窗
    model3.customPopView = customPopView3;
    /// 延迟弹出的时间
    model3.popDelay = 0;
    /// 动画样式
    model3.animateStyle = ZFJAnimateFromBottom;
    [dataArray addObject:model3];
    
    /// 第五个弹窗
    UIView *customPopView4 = [[UIView alloc] init];
    customPopView4.backgroundColor = kRandomColor();
    customPopView4.frame = CGRectMake(0, 0, 200, 200);
    customPopView4.layer.masksToBounds = YES;
    customPopView4.layer.cornerRadius = 8;
    ZFJPopModel *model4 = [[ZFJPopModel alloc] init];
    /// 自定义弹窗
    model4.customPopView = customPopView4;
    /// 延迟弹出的时间
    model4.popDelay = 0;
    /// 动画样式
    model4.animateStyle = ZFJAnimateByScale;
    [dataArray addObject:model4];
    
    /// 第六个弹窗
    UIView *customPopView5 = [[UIView alloc] init];
    customPopView5.backgroundColor = kRandomColor();
    customPopView5.frame = CGRectMake(0, 0, 200, 400);
    customPopView5.layer.masksToBounds = YES;
    customPopView5.layer.cornerRadius = 8;
    ZFJPopModel *model5 = [[ZFJPopModel alloc] init];
    /// 自定义弹窗
    model5.customPopView = customPopView5;
    /// 延迟弹出的时间
    model5.popDelay = 0;
    /// 动画样式
    model5.animateStyle = ZFJAnimateNone;
    [dataArray addObject:model5];
    
    /// 错误码的回调
    [ZFJPopManager sharedInstance].popErrorCodeBlock = ^(ZFJPopErrorCode errorCode) {
        NSLog(@"errorCode == %ld",errorCode);
    };
    /// 添加弹框的数据源数组
    [[ZFJPopManager sharedInstance] addPopModelsFromArray:dataArray];
    /// 开始弹窗
    [[ZFJPopManager sharedInstance] startPopView];
    /// 所有的弹窗都结束了
    [ZFJPopManager sharedInstance].popFinishedBlock = ^{
        NSLog(@"结束了");
    };
    /// 倒计时的回调
    [ZFJPopManager sharedInstance].popCountDownBlock = ^(ZFJPopModel *model, NSInteger countDown) {
        /// 这里面可以回调给自定义的到时间弹窗视图的UI展示
        if(model == model0){
            customPopView0.text = [NSString stringWithFormat:@"%ld", countDown];
        }
    };
}

- (void)button1Click{
    [[ZFJPopManager sharedInstance] stopPopView];
    
//    /// 这是你的自定义视图弹窗
//    UIView *customPopView = [[UIView alloc] init];
//    ///
//    ZFJPopView *popView = [[ZFJPopView alloc] initWithPopView:customPopView];
//    /// 弹窗动画类型
//    popView.animateStyle = ZFJAnimateFromTop;
//    /// 弹出弹出
//    [popView showPopAnimationView];
//    /// 弹出加载window上
//    [[ZFJPopManager sharedInstance].zfj_keyWindow addSubview:popView];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
